{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from time import time\n",
    "from random import sample\n",
    "import markdown\n",
    "import sys, os\n",
    "sys.path.append(\"C:\\\\Users\\\\Administrator\\\\Desktop\\\\Deeptrain\")\n",
    "os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Deeptrain.settings')\n",
    "os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rest.settings')\n",
    "os.environ[\"DJANGO_ALLOW_ASYNC_UNSAFE\"] = \"true\"\n",
    "\n",
    "import django\n",
    "django.setup()\n",
    "\n",
    "from utils.benchmark import *\n",
    "from utils.cache import hash_cache_process_safe, execute_or_get\n",
    "from utils.parse_markdown import parse_markdown\n",
    "\n",
    "\n",
    "population = list(\"asdfjlk;qwertyuiopzxcvbnm,./;'[]1234567890-=`~_+?<>###``         \")\n",
    "\n",
    "\n",
    "def generate_code(stride=10**3):\n",
    "    return \"\".join([v\n",
    "                    for _ in range(stride)\n",
    "                    for v in sample(population, 10)])\n",
    "\n",
    "def req():\n",
    "    return parse_markdown(generate_code())\n",
    "cache_req = lambda: execute_or_get(\"markdown\", req)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "13.181858752509525"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fps_analysis(req, count=10)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "66661.96220537517"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fps_analysis(cache_req, count=1000)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "12.828125"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(cache_req()) / 1024"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
